#ifndef _STATE_H
#define _STATE_H

class State;
class StateListener{
public:
	virtual ~StateListener(){}
	virtual void ManageState(const String& id, State* state) = 0;
	virtual State* FindById(const String& id) = 0;
	virtual void ChangeState(State* state) = 0;
	virtual bool PushState(State* state) = 0;
	virtual void PopState() = 0;
	virtual void Shut() = 0;
};

class State{
public:
	/*State(StateListener* parent, const String& id) : m_parent(parent) {
		m_parent->ManageState(id, this);
	}*/
	//virtual ~State(void){}
	template <typename T>
	static void Create(StateListener* parent, const String& id){
		T* state = new T;
		state->m_parent = parent;
		parent->ManageState(id, state);
	}
	void Destroy() { delete this; }
	void SetSystems(Systems* systems) { m_systems = systems; }

	virtual void Init() = 0;
	virtual void Shut() = 0;

	virtual void Update(float deltatime) = 0;
	virtual void Render() = 0;
	virtual bool Pause() { return false; }
	virtual void Resume() = 0;


protected:
	State(void){}
	virtual ~State(void){}

	State* FindById(const String& id) { return m_parent->FindById(id); }
	void ChangeState(State* state) { m_parent->ChangeState(state); }
	void PushState(State* state) { m_parent->PushState(state); }
	void PopState() { m_parent->PopState(); }
	void Shutdown() { m_parent->Shut(); }

	Systems* m_systems;
	StateListener* m_parent;
};

#endif //_STATE_H